package com.shenhangye.pushlive.gles

import android.graphics.SurfaceTexture
import android.view.Surface

class WindowSurface:EglSurfaceBase {
    private var mSurface: Surface? = null
    private var mReleaseSurface = false
    constructor(eglCore: EglCore,surface: Surface,releaseSurface: Boolean):super(eglCore){
        createWindowSurface(surface)
        this.mSurface=surface;
        this.mReleaseSurface=releaseSurface
    }

    /**
     * Associates an EGL surface with the SurfaceTexture.
     */
    constructor(eglCore: EglCore, surfaceTexture: SurfaceTexture): super(eglCore) {
        createWindowSurface(surfaceTexture)
    }
    /**
     * Releases any resources associated with the EGL surface (and, if configured to do so,
     * with the Surface as well).
     * <p>
     * Does not require that the surface's EGL context be current.
     */
    fun release(){
        releaseEglSurface()
        mSurface?.let {
            if (mReleaseSurface){
                mSurface?.release()
            }
        }
        mSurface=null
    }


    fun recreate(newEglCore:EglCore){
        mEglCore=newEglCore;
        createWindowSurface(mSurface!!);
    }
}